package com.yy.studyspringboot.controller;

import com.yy.studyspringboot.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api("用户管理api")
public class TestController {

    @ApiOperation("测试服务器健康")
    @GetMapping("/")
    public String test(){
        return "Access to success :" + LocalDateTime.now();
    }

    @ApiOperation("查询用户信息")
    @PostMapping("test/files")
    public void testFiles(MultipartFile[] files){
        System.out.println(files);
    }

    @GetMapping("test/filter")
    public void testFilter(){
        System.out.println("测试过滤器");
    }

    //,value = "application/text "
    @PostMapping(value = "/sss",name = "application/text")
    public void testFiles(@RequestBody String sender){
        System.out.println();
    }
    @PostMapping(value = "/sss2")
    public void testFiles(@RequestBody TestObj testObj){
        System.out.println();

        new TestObj().tt();
    }

    /**
     * 测试容器初始化添加值
     * @param args
     */
    public static void main(String[] args) {
        List<String> indexList = new ArrayList<String>() {
            {
                this.add("a1a");
                this.add("a2");
                this.add("a3");
                this.add("a4");
                this.add("a5");
            }
            @Override
            public boolean add(String s) {
                return super.add(s);
            }
        };
        System.out.println(indexList);
    }


    /**
     * 测试返回图片流
     * @param response
     * @throws IOException
     */
    @GetMapping(value = "/test/outStream")
    public void testOutStream(HttpServletResponse response) throws IOException {
        BufferedImage bufImg = ImageIO.read(new File("C:\\Users\\Admin\\Pictures\\Camera Roll\\1832b853244.jpg"));
        String picType = "url=X:/GENDMS_FILE/gendmsfile/202106/1832b853244.jpg".split("\\.")[1];
        ServletOutputStream outStream = response.getOutputStream();
        ImageIO.write(bufImg, picType, outStream);
    }

}
